/**
 * Copyright © Jack魏 2022 - 2022, All Rights Reserved.
 */

package com.jack.thread.t01;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * Java天生多线程
 *
 * @author Jack魏
 * @since 2022/11/13 23:20
 */
public class JavaThread {
    /**
     * 主方法入口
     *
     * @param args 执行参数
     */
    public static void main(String[] args) {
        // Java 虚拟机线程管理接口
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        // 线程和线程堆栈信息
        ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false, false);
        // 打印信息
        for (ThreadInfo threadInfo : threadInfos) {
            System.out.println("[" + threadInfo.getThreadId() + "]" + " " + threadInfo.getThreadName());
        }
    }

    /**
     * 输出信息如下：
     *
     * [1] main
     * [2] Reference Handler
     * [3] Finalizer
     * [4] Signal Dispatcher
     * [5] Attach Listener
     * [21] Common-Cleaner
     * [22] Monitor Ctrl-Break
     * [23] Notification Thread
     */
}
